﻿<Window x:Class="ScrumFactory.ProjectTeam.MemberLookup"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:SF_CompViewModel="clr-namespace:ScrumFactory.Composition.ViewModel;assembly=ScrumFactory.Composition"
        xmlns:props="clr-namespace:ScrumFactory.ProjectTeam.Properties"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
         xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"  
        
        x:Name="thisView"
        
        SnapsToDevicePixels="True"
        
        Style="{StaticResource FactoryWindow}"
        WindowStartupLocation="CenterOwner"
        ShowInTaskbar="False"
        Title="{Binding Title}"        
        Width="630" Height="400">
    
    <Window.Resources>

        <ObjectDataProvider  x:Key="occupationFilterList" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="SF_CompViewModel:Occupations"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <DataTemplate x:Key="OccupationFilterDataTemplate">
            <Grid HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Viewbox Width="14" Height="14" Grid.Column="0" HorizontalAlignment="Left">
                    <Path Style="{StaticResource DayAllocationPath}"/>
                </Viewbox>
                <TextBlock Grid.Column="1"                    
                    Text="{Binding ., Converter={StaticResource LocalizeConverter},
                    ConverterParameter='ScrumFactory.ProjectTeam.MemberLookup,ScrumFactory.ProjectTeam'}"/>
            </Grid>                
        </DataTemplate>
        

    </Window.Resources>
    
    <Grid Background="{StaticResource PanelBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>            
        </Grid.RowDefinitions>
        
        <ToolBar Grid.Row="0">
            <TextBox
                Text="{Binding SearchFilterText, UpdateSourceTrigger=PropertyChanged}"
                Style="{StaticResource SearchTextBox}" Width="330"
                ToolTip="{x:Static props:Resources.Search_tooltip}"/>
            <ComboBox               
                Style="{StaticResource {x:Type ComboBox}}"
                ItemsSource="{Binding Source={StaticResource occupationFilterList}}"
                Width="200"
                ItemTemplate="{StaticResource OccupationFilterDataTemplate}"
                SelectedItem="{Binding OccupationFilter}"/>                
        </ToolBar>

        <ListView Grid.Row="1"  
                  x:Name="listView"
                  Background="Transparent"
                  Margin="3"
                  ItemsSource="{Binding FilteredMembers}"
                  SF_Helpers:ListViewColumnsExtension.Stretch="True"
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="{x:Static props:Resources.Resource}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid
                                    SF_Comp:CommandBehavior.RoutedEventName="MouseLeftButtonDown"
                                    SF_Comp:CommandBehavior.TheCommandToRun="{Binding ElementName=thisView, Path=DataContext.SelectMemberCommand}"
                                    SF_Comp:CommandBehavior.TheCommandParameter="{Binding}">
                                    
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <ContentControl
                                        Width="32" Height="32"
                                        Grid.Column="0"
                                        Margin="0,0,20,0"
                                        HorizontalAlignment="Center" VerticalAlignment="Center"
                                        Style="{StaticResource MemberImageControlStyle}"/>
                                    <StackPanel Grid.Column="1">
                                        <TextBlock Foreground="{StaticResource TitleTextBrush}" Text="{Binding MemberProfile.FullName}" TextTrimming="CharacterEllipsis"/>
                                        <TextBlock Foreground="{StaticResource SubTextBrush}" FontSize="{StaticResource SmallFontSize}" Text="{Binding MemberProfile.Skills}"
                                                   TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{x:Static props:Resources.Contact_data}" Width="150">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Foreground="{StaticResource SubTextBrush}" FontSize="{StaticResource SmallFontSize}" Text="{Binding MemberProfile.ContactData}"
                                           TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>                                
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{x:Static props:Resources.Occupation}" Width="80">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>                                
                                <Path                  
                                    StrokeLineJoin="Round" SnapsToDevicePixels="True"
                                    DataContext="{Binding MemberProfile.DayOccupation}"
                                    Style="{StaticResource DayAllocationPath}"/>                                
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{x:Static props:Resources.Add_to_project}" Width="80">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Button 
                                        Command="{Binding ElementName=thisView, Path=DataContext.SelectMemberCommand}"
                                        CommandParameter="{Binding .}"
                                        Width="24" Height="24">
                                        <Button.Style>
                                            <Style BasedOn="{StaticResource AddCircleButton}" TargetType="{x:Type Button}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsMemberSelected}" Value="True">
                                                        <Setter Property="Button.Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Button.Style>
                                    </Button>
                                    <TextBlock
                                        Foreground="Red"
                                        TextAlignment="Center"
                                        TextWrapping="Wrap"
                                        Text="{x:Static props:Resources.Member_added}">
                                        <TextBlock.Style>
                                            <Style>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsMemberSelected}" Value="False">
                                                        <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>
                                </Grid>                                
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                </GridView>
            </ListView.View>

        </ListView>

        <Grid
            Grid.Row="1"
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Image Grid.Column="0" Source="/Images/information.png" Margin="3" VerticalAlignment="Top" Width="16" Height="16" Stretch="Uniform" />
            <TextBlock Grid.Column="1" TextWrapping="Wrap" >
                <TextBlock TextWrapping="Wrap"
                           Foreground="Black" 
                           Text="{x:Static props:Resources.No_items_were_found}"/><LineBreak/>
                <TextBlock TextWrapping="Wrap"                            
                           Margin="0,10,0,0" Foreground="{StaticResource SubTextBrush}" Text="{x:Static props:Resources.No_items_were_found_tip}"/>
            </TextBlock>
            <Grid.Style>
                <Style>
                    <Setter Property="Grid.Visibility" Value="Collapsed"/>
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding ElementName=listView, Path=HasItems}" Value="False"/>
                                <Condition Binding="{Binding IsLoadingData}" Value="False"/>
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Grid.Visibility" Value="Visible"/>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
        </Grid>

    </Grid>
</Window>
